<?php

class Admin_Model_District extends Zend_Db_Table_Abstract
{
    protected $_name = 'district';
    public function getDataByProvince($province){
    	$query = $this->select()
                        ->from($this->_name)
                        ->where('provinceid=?', (int)$province);
    	return $this->fetchAll($query);
    }
    public function getAllData(){        
        $query = $this->select()
                    ->setIntegrityCheck(false)                        
                    ->from(array('d'=>$this->_name))
                    ->joinLeft(array('p'=>'province'),'d.provinceid = p.provinceid', array('p.provinceid as provinceId','p.name as provinceName'));                        
        return $this->fetchAll($query);        
    }
    public function getDataByprovinceid($proId){
        $query = $this->select()                        
                    ->setIntegrityCheck(false)                        
                    ->from(array('d'=>$this->_name))
                    ->joinLeft(array('p'=>'province'),'d.provinceid = p.provinceid', array('p.provinceid as provinceId','p.name as provinceName'))
                    ->where('d.provinceid = ?',(int)$proId);
        return $this->fetchAll($query);
    }
    public function getDataByType($type){
        $query = $this->select()                        
                    ->setIntegrityCheck(false)                        
                    ->from(array('d'=>$this->_name))
                    ->joinLeft(array('p'=>'province'),'d.provinceid = p.provinceid', array('p.provinceid as provinceId','p.name as provinceName'))
                    ->where("type = '".$type."'");
        return $this->fetchAll($query);
    }        
    public function addData($data){        
        $data = array('districtId'  => $data['districtId'],
                'districtName'      => $data['districtName'],                
                'type'              => $data['type'],
                'location'          => $data['location'],
                'provinceid'        => $data['provinceid']);                                
        $idAdd = $this->insert($data);        
        return $idAdd;
    }
    public function updateData($disId = '',$data){        
        $data = array('districtName'=> $data['districtName'],                
                'type'              => $data['type'],
                'location'          => $data['location'],
                'provinceid'        => $data['provinceid']);                            
        return $this->update($data, 'districtId = '.(int)$disId);
    }            
    public function deleteData($id){        
        $this->delete('districtId = '.(int)$id);
    }
}

